import 'package:banyou_app/app/util/string_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

class LiuyanController extends GetxController {
  // final dynamics = {}.obs;
  final userMap = {}.obs;
  final comments = [].obs;
  final sendEnable = false.obs;
  final textController = TextEditingController();
  final text = ''.obs;

  @override
  void onInit() {
    userMap.value = Get.arguments ?? {};
    // dynamics.value = userMap['Dynamics'] ?? {};
    comments.value = userMap['Comments'] ?? [];
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  checkInput() {
    bool a = isNotEmpty(text.value);
    if (a) {
      sendEnable.value = true;
    } else {
      sendEnable.value = false;
    }
  }

  send() {
    if (text.isEmpty) {
      EasyLoading.showToast('请输入评论内容');
    } else {
      FocusScopeNode currentFocus = FocusScope.of(Get.context!);
      if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
        FocusManager.instance.primaryFocus!.unfocus();
      }
      EasyLoading.show();
      Future.delayed(Duration(seconds: 2), () {
        EasyLoading.dismiss();
        textController.text = '';
        text.value = '';
        checkInput();
        EasyLoading.showToast('发表成功，请等待审核!');
      });
    }

    // messages.addIf(text.value.length > 0, text.value);
  }

  @override
  void onClose() {}
}
